package com.liuxvru.project.system.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.ProjectUserAssignment;
import com.liuxvru.project.service.IProjectUserAssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目与人员分配Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/project/projectUserAssignment")
public class ProjectUserAssignmentController extends BaseController {
    @Autowired
    private IProjectUserAssignmentService projectUserAssignmentService;

    /**
     * 查询项目与人员分配列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectUserAssignment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectUserAssignment projectUserAssignment) {
        startPage();
        List<ProjectUserAssignment> list = projectUserAssignmentService.selectProjectUserAssignmentList(projectUserAssignment);
        return getDataTable(list);
    }

    /**
     * 导出项目与人员分配列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectUserAssignment:export')")
    @Log(title = "项目与人员分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectUserAssignment projectUserAssignment) {
        List<ProjectUserAssignment> list = projectUserAssignmentService.selectProjectUserAssignmentList(projectUserAssignment);
        ExcelUtil<ProjectUserAssignment> util = new ExcelUtil<ProjectUserAssignment>(ProjectUserAssignment.class);
        util.exportExcel(response, list, "项目与人员分配数据");
    }

    /**
     * 获取项目与人员分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:projectUserAssignment:query')")
    @GetMapping(value = "/{assignmentId}")
    public AjaxResult getInfo(@PathVariable("assignmentId") Long assignmentId) {
        return success(projectUserAssignmentService.getById(assignmentId));
    }

    /**
     * 新增项目与人员分配
     */
    @PreAuthorize("@ss.hasPermi('project:projectUserAssignment:add')")
    @Log(title = "项目与人员分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectUserAssignment projectUserAssignment) {
        return toAjax(projectUserAssignmentService.save(projectUserAssignment));
    }

    /**
     * 修改项目与人员分配
     */
    @PreAuthorize("@ss.hasPermi('project:projectUserAssignment:edit')")
    @Log(title = "项目与人员分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectUserAssignment projectUserAssignment) {
        return toAjax(projectUserAssignmentService.updateById(projectUserAssignment));
    }

    /**
     * 删除项目与人员分配
     */
    @PreAuthorize("@ss.hasPermi('project:projectUserAssignment:remove')")
    @Log(title = "项目与人员分配", businessType = BusinessType.DELETE)
    @DeleteMapping("/{assignmentIds}")
    public AjaxResult remove(@PathVariable Long[] assignmentIds) {
        return toAjax(projectUserAssignmentService.removeById(assignmentIds));
    }
}
